﻿
using ZR.Model.Models.ProductionControl;

namespace CKS.PLC.Core.Siemens
{
    public interface ISiemensClient
    {
        /// <summary>
        /// 是否连接
        /// </summary>
        bool IsConnected { get; set; }

        /// <summary>
        /// 心跳值
        /// </summary>
        int HeartValue {  get; set; }

        /// <summary>
        /// 当前PLC是否在线
        /// </summary>
        bool IsOnline { get; set; }

        /// <summary>
        /// PLC信息
        /// </summary>
        PlcConfig PlcInfo { get; set; }

        /// <summary>
        /// 连接PLC
        /// </summary>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        Task ConnectPlc(CancellationToken cancellation);

        /// <summary>
        /// 心跳方法
        /// </summary>
        Task DoHeart();

        /// <summary>
        /// Execute
        /// </summary>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        Task Execute(CancellationToken cancellation);

        /// <summary>
        /// ExecuteMain
        /// </summary>
        /// <returns></returns>
        Task ExecuteMain();

        /// <summary>
        /// ExecuteSubscriptionAction
        /// </summary>
        /// <param name="value"></param>
        void ExecuteSubscriptionAction(DecodeValue value);
       
        /// <summary>
        /// 启动方法
        /// </summary>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        Task StartAsync(CancellationToken cancellation);

        /// <summary>
        /// ReadBytesAsync
        /// </summary>
        /// <param name="db"></param>
        /// <param name="startByteAdr"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        Task<byte[]> ReadBytesAsync(int db, int startByteAdr, int count);

        /// <summary>
        /// ReadInt16
        /// </summary>
        /// <param name="db"></param>
        /// <param name="startByteAdr"></param>
        /// <returns></returns>
        short ReadInt16(int db, int startByteAdr);

        /// <summary>
        /// WriteInt16
        /// </summary>
        /// <param name="db"></param>
        /// <param name="startByteAdr"></param>
        /// <param name="value"></param>
        void WriteInt16(int db, int startByteAdr, Int16 value);

        /// <summary>
        /// SetValue
        /// </summary>
        /// <param name="s7Point"></param>
        /// <param name="configValue"></param>
        void SetValue(CksPlcDataPosition s7Point, string configValue);

        /// <summary>
        /// GetValue
        /// </summary>
        /// <param name="s7Point"></param>
        /// <returns></returns>
        object GetValue(CksPlcDataPosition s7Point);
    }
}